package com.hooper.threadpool.demo;

import cn.hutool.core.collection.CollectionUtil;

import java.util.List;

/**
 * 需求:
 * 编写一个线程类,需要继承Thread类,设计一个属性,
 * 用于保存线程的名字;设计一个集合,用于保存所有的任务;
 *
 * @author Tim Hooper
 * @version 1.0
 * @time 2023/03/02/18:07
 */
public class MyWorker extends Thread {

    private String name;
    private final List<Runnable> tasks;

    public MyWorker(String name, List<Runnable> tasks) {
        super(name);
        this.tasks = tasks;
    }

    @Override
    public void run() {
        if (CollectionUtil.isEmpty(tasks)) {
            return;
        }
        while (tasks.size() > 0) {
            Runnable target = tasks.remove(0);
            target.run();
        }
    }

}
